/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.sql.Time;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Andre
 */
@Entity
@Table(name = "compra")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Compra.findAll", query = "SELECT c FROM Compra c"),
    @NamedQuery(name = "Compra.findByIdCompra", query = "SELECT c FROM Compra c WHERE c.idCompra = :idCompra"),
    @NamedQuery(name = "Compra.findByDataCompra", query = "SELECT c FROM Compra c WHERE c.dataCompra = :dataCompra")})
public class Compra implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idCompra")
    private Integer idCompra;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "dataCompra")
    @Temporal(TemporalType.DATE)
    private Date dataCompra;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "compra")
    private List<ItensCompra> itensCompraList;
    
    @JoinColumn(name = "idFornecedor", referencedColumnName = "idPessoa")
    @ManyToOne(optional = false)
    private Fornecedor fornecedor;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "compra")
    private List<CondicoesCompra> condicoesCompraList;

    public Compra() {
    }

    public Compra(Date dataCompra) {
        this.dataCompra = dataCompra;
    }

    public Integer getIdCompra() {
        return idCompra;
    }

    public Date getDataCompra() {
        return dataCompra;
    }

    public void setDataCompra(Date dataCompra) {
        this.dataCompra = dataCompra;
    }

    public Fornecedor getFornecedor() {
        return fornecedor;
    }

    public void setFornecedor(Fornecedor fornecedor) {
        this.fornecedor = fornecedor;
    }

    public List<CondicoesCompra> getCondicoesCompraList() {
        return condicoesCompraList;
    }

    public void setCondicoesCompraList(List<CondicoesCompra> condicoesCompraList) {
        this.condicoesCompraList = condicoesCompraList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCompra != null ? idCompra.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Compra)) {
            return false;
        }
        Compra other = (Compra) object;
        if ((this.idCompra == null && other.idCompra != null) || (this.idCompra != null && !this.idCompra.equals(other.idCompra))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Compra[ idCompra=" + idCompra + " ]";
    }

    /**
     * @return the itensCompraList
     */
    public List<ItensCompra> getItensCompraList() {
        return itensCompraList;
    }

    /**
     * @param itensCompraList the itensCompraList to set
     */
    public void setItensCompraList(List<ItensCompra> itensCompraList) {
        this.itensCompraList = itensCompraList;
    }
    
}
